package com.neusoft.elm;
import java.util.Scanner;

import com.neusoft.elm.po.Admin;
import com.neusoft.elm.view.AdminView;
import com.neusoft.elm.view.BusinessView;
import com.neusoft.elm.view.impl.AdminViewImpl;
import com.neusoft.elm.view.impl.BusinessViewImpl;

public class ElmAdminEntry {

	public void work() {
		Scanner input = new Scanner(System.in);
		
		System.out.println("----------------------------------");
        System.out.println("|      欢迎下次光临饿了么后台管理平台                   |");
        System.out.println("----------------------------------");
        
		AdminView adminView = new AdminViewImpl(); 
		BusinessView businessView = new BusinessViewImpl();
        boolean loginSuccess = false;
        
        while (!loginSuccess) {
            Admin admin = adminView.login();
	
		if(admin!=null) {
			loginSuccess = true;
			
			int menu = 0;
			while(menu != 8) {
				System.out.println("\n------------- -----------");
                System.out.println("| 1. 所有商家列表                                   |");
                System.out.println("| 2. 搜索商家                                          |");
                System.out.println("| 3. 新建商家                                          |");
                System.out.println("| 4. 删除商家                                          |");
                System.out.println("| 5. 统计商家数量                                   |");
                System.out.println("| 6. 修改密码                                          |");
                System.out.println("| 7. 修改账户名                                      |");
                System.out.println("| 8. 退出系统                                          |");
                System.out.println("---------------------------");
			System.out.println("请输入你的选择:");
			while (!input.hasNextInt()) {
                System.out.println("输入无效，请重新你的选择：");
                input.next(); 
             }
			
			menu = input.nextInt();
			switch(menu) {
			    case 1:
			    	businessView.listBusinessAll();
			    	break;
			    case 2:
			    	businessView.listBusiness();
			    	break;
			    case 3:
			    	businessView.addBusiness();
			    	break;
			    case 4:
			    	businessView.removeBusiness();
			    	break;
			    case 5:
			    	businessView.countBusiness();
			    	break;
			    case 6:
			    	adminView.updateAdminPassword(admin);
			    	break;
			    case 7:
			    	adminView.updateAdminName(admin);
			    	break;
			    case 8:
			    	System.out.println("----------------------------------");
			        System.out.println("|      欢迎下次光临饿了么后台管理平台                   |");
			        System.out.println("----------------------------------");
			    	break;
			    default:
			    	System.out.println("没有这个选项！\n");
			        break;	
			}
			
			if (menu == 8) {
                System.out.println("是否重新登录？(y/n)");
                String choice = input.next();
                if (choice.equals("y")) {
                    loginSuccess = false; 
                    break;
                } else if (choice.equals("y")) {
                	System.out.println("----------------------------------");
                    System.out.println("|      欢迎下次光临饿了么后台管理平台                   |");
                    System.out.println("----------------------------------");
                    return;
                } else {
                    System.out.println("输入无效！程序退出。");
                    return;
                }
            }
			
			}	
		}else {
			System.out.println("管理员名称或密码输入错误!");
			System.out.println("请重新输入管理员账户和密码！");}
		}
		 
        }
	
	public static void main(String[] args) {
		new ElmAdminEntry().work();
	}
}

	

